home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tchk21ex.zip / DEMOTIME.C < prev    next >
C/C++ Source or Header  |  1989-06-06  |  3KB  |  87 lines

  1. /* TCHK 2.1 - Howard Kapustein's Turbo C library        6-6-89      */
  2. /* Copyright (C) 1988,1989 Howard Kapustein.  All rights reserved.  */
  3.  
  4. /* demotime.c  -  used for testing TCHK time conversions */
  5.  
  6. #include <howard.h>
  7. #include <timehk.h>
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. void main();
  15.  
  16. void main()
  17. {
  18.     extern int _argc;
  19.     extern char **_argv;
  20.     void *generic;
  21.     char buff[80], temp[80], temp2[80];
  22.     double dbl, dbl2;
  23.     struct time now, t, t2;
  24.     int stype, dtype;
  25.  
  26.     if (_argc<3) {
  27.         printf("DemoTime is a demonstration program of the time conversions of TCHK.\n\n");
  28.         printf("Usage:  demotime stype dtype\n\n");
  29.         printf("    demotime will convert the current time from stype format\n");
  30.         printf("    to dtype format. See TCHK.DOC for more details\n");
  31.         exit(1);
  32.     }
  33.  
  34.     stype = atoi(_argv[1]);
  35.     dtype = atoi(_argv[2]);
  36.     if (stype<1 || stype>24 || dtype<1 || dtype>24) {
  37.         printf("Invalid format (must be 1-24)\n");
  38.         exit(2);
  39.     }
  40.  
  41. /*  for this demo, I get the current time, convert it to format 21
  42.     (0HH:MM:SS:CC) via a sprintf() and then convert it to format stype
  43.     for the test of time_convert(s,d,stype,dtype).                                      */
  44.  
  45.     gettime(&now);
  46.     sprintf(buff,"%d:%02d:%02d.%02d",(int)(now.ti_hour),(int)(now.ti_min),(int)(now.ti_sec),(int)(now.ti_hund));
  47.     printf("Current time: %s\nStype %d:  ",buff,stype);
  48.     switch (stype) {
  49.         case 7: { time_convert(buff,&t,21,stype);
  50.                   printf("%d %d %d %d",t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
  51.                   generic = (void *) &t;
  52.                   break; }
  53.         case 8:
  54.         case 9:
  55.         case 10:
  56.         case 11:
  57.         case 12: { time_convert(buff,&dbl,21,stype);
  58.                    printf("%lf",dbl);
  59.                    generic = (void *) &dbl;
  60.                    break; }
  61.         default: { time_convert(buff,temp,21,stype);
  62.                    printf("%s",temp);
  63.                    generic = (void *) temp;
  64.                    break; }
  65.     }
  66.     printf("   ->   Dtype %d:  ",dtype);
  67.     switch (dtype) {
  68.         case 7: { time_convert(generic,&t2,stype,dtype);
  69.                   printf("%d %d %d %d",t2.ti_hour,t2.ti_min,t2.ti_sec,t2.ti_hund);
  70.                   break; }
  71.         case 8:
  72.         case 9:
  73.         case 10:
  74.         case 11:
  75.         case 12: { time_convert(generic,&dbl2,stype,dtype);
  76.                    printf("%lf",dbl2);
  77.                    break; }
  78.         default: { time_convert(generic,temp2,stype,dtype);
  79.                    printf("%s",temp2);
  80.                    break; }
  81.     }
  82.     printf("\n");
  83.  
  84. /* quit */
  85.     exit(0);
  86. }
  87.